package cn.tkb.user.controller;

import cn.tkb.basic.exception.BusinessException;
import cn.tkb.basic.util.AjaxResult;
import cn.tkb.user.dto.LoginDto;
import cn.tkb.user.service.ILoginService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILoginService loginService;
    @PostMapping("/account")
    public AjaxResult accountLogin(@RequestBody LoginDto dto){
        try {

            Map<String,Object> map =loginService.accountLogin(dto);
            return AjaxResult.success().setResultObj(map);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.fail("系统繁忙，请稍后重试！！！");
        }
    }
    @PostMapping("/wechat")
    public AjaxResult wechat(@RequestBody Map<String,String> params){
        try {
            return loginService.wechat(params);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.fail("系统繁忙，请稍后重试！！！");
        }
    }
    @PostMapping("/binderWechat")
    public AjaxResult binderWechat(@RequestBody Map<String,String>params){
        try {
            Map<String,Object> map =loginService.binderWechat(params);
            return AjaxResult.success().setResultObj(map);
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.fail(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.fail("系统繁忙，请稍后重试！！！");
        }
    }
}
